package net.roobook.cms.common.entity;

import java.io.Serializable;
import java.util.List;

/**
 * @author cos
 * @email 327878610@qq.com
 * @link https://roobook.net
 * @Description 数据传输对象DTO，用于将处理后的结果对象封装
 * @date 2023/9/24 10:30
 **/
public class ResResult  implements Serializable {
    private static final long serialVersionUID = -7183680631393026093L;
    // 结果集
    private Object data;

    // 结果集，主要用于查询
    private List list;
    // 返回状态（默认返回状态为成功，初始化实体后默认状态）
    private String state = StateCodeEnum.HTTP_SUCCESS.getCode();

    private boolean success;
    // info信息
    private String info;
    public ResResult() {
    }

    public ResResult(boolean success, String state, Object model, String info) {
        this.success = success;
        this.state = state;
        this.data = model;
        this.info = info;
    }

    public ResResult(boolean success, String state, String info) {
        this.success = success;
        this.state = state;
        this.info = info;
    }


    public static class Factory{
        public static ResResult newInstance(boolean success, String status, Object model, String info) {
            if(model instanceof List){
                ResResult resResult = new ResResult(success, status, info);
                resResult.setList((List)model);
                return resResult;
            }else{
                return new ResResult(success, status, model, info);
            }
        }
    }


    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getInfo() {
        return info;
    }

    public void setInfo(String info) {
        this.info = info;
    }

    public List getList() {
        return list;
    }

    public void setList(List list) {
        this.list = list;
    }
}
